package com.af.monitorModule.controller.util;

import com.af.monitorModule.common.ResultEnum;
import com.af.monitorModule.timmer.DaySummary;
import com.af.monitorModule.util.RestUtil;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/util")
public class UtilController {

    @Autowired
    private DaySummary daySummary;

    @PostMapping("/checkUrlConnect")
    public JSONObject checkUrlConnect(@RequestBody JSONObject data){
        String type = data.getString("type");
        String url = data.getString("url");

        JSONObject res = ResultEnum.OK.getResult();
        res.put("open",RestUtil.checkUrl(url,3,type));
        return res;
    }

    @GetMapping("/sendDay")
    public JSONObject sendDay(){
        daySummary.sendYesterdayStatistics();
        return ResultEnum.OK.getResult();
    }
}
